﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using Applee.FractCommon;
using System.Drawing.Drawing2D;

namespace Applee.DurerFract
{
    public class DurerPentagon : BaseShape
    {
        public DurerPentagon()
        {
            points = new PointF[6] 
                { 
                    new PointF(), 
                    new PointF(), 
                    new PointF(),
                    new PointF(), 
                    new PointF(), 
                    new PointF() 
                };
        }

        //public DurerPentagon(DurerPentagon pentagon)
        //{
        //    Points[0] = pentagon.Points[0];
        //    Points[1] = pentagon.Points[1];
        //    Points[2] = pentagon.Points[2];
        //    Points[3] = pentagon.Points[3];
        //    Points[4] = pentagon.Points[4];
        //    Points[5] = pentagon.Points[5];

        //    mColor = pentagon.mColor;
        //}

        //private PointF[] points = new PointF[6] 
        //{ 
        //    new PointF(), 
        //    new PointF(), 
        //    new PointF(),
        //    new PointF(), 
        //    new PointF(), 
        //    new PointF() 
        //};

        //public PointF[] Points
        //{
        //    get { return points; }
        //    set { points = value; }
        //}

        //private Color mColor = new Color();
        //public Color Color
        //{
        //    get { return mColor; }
        //    set { mColor = value; }
        //}

        ////以第一个点为基点移动到PointTo
        //public DurerPentagon MovePentagon(PointF pointBase, PointF pointTo)
        //{
        //    float x = pointTo.X - pointBase.X;
        //    float y = pointTo.Y - pointBase.Y;

        //    Points[0] = new PointF(Points[0].X + x, Points[0].Y + y);
        //    Points[1] = new PointF(Points[1].X + x, Points[1].Y + y);
        //    Points[2] = new PointF(Points[2].X + x, Points[2].Y + y);
        //    Points[3] = new PointF(Points[3].X + x, Points[3].Y + y);
        //    Points[4] = new PointF(Points[4].X + x, Points[4].Y + y);
        //    Points[5] = new PointF(Points[5].X + x, Points[5].Y + y);

        //    return this;
        //}

        ////public static DurerPentagon CreatePentagon(PointF point, float fLength)
        ////{
        ////    DurerPentagon pentagon = new DurerPentagon(point, fLength);
        ////    return pentagon;
        ////}

        ////private void Initilize(PointF point, float fLength)
        ////{
        ////    //lenth:L
        ////    //a circumscribed circle radius: R
        ////    //R = L / sin36 * 0.5
        ////    float radius = -Math.Abs(fLength / (float)Math.Sin(36.0) * 0.5F);

        ////    float lctAngle = (float)(18.0F * Math.PI / 180);
        ////    float lcbAngle = (float)(36.0F * Math.PI / 180);

        ////    //(0, R)
        ////    Points[0] = new PointF(point.X, radius + point.Y);

        ////    //(R*cos18, R*sin18)
        ////    Points[1] = new PointF(radius * (float)Math.Cos(lctAngle) + point.X,
        ////        radius * (float)Math.Sin(lctAngle) + point.Y);

        ////    //(R*sin36, -R*cos36)
        ////    Points[2] = new PointF(radius * (float)Math.Sin(lcbAngle) + point.X,
        ////        -radius * (float)Math.Cos(lcbAngle) + point.Y);

        ////    //(-R*sin36, -R*cos36)
        ////    Points[3] = new PointF(-radius * (float)Math.Sin(lcbAngle) + point.X,
        ////        -radius * (float)Math.Cos(lcbAngle) + point.Y);

        ////    //(-R*cos18, R*sin18)
        ////    Points[4] = new PointF(-radius * (float)Math.Cos(lctAngle) + point.X,
        ////        radius * (float)Math.Sin(lctAngle) + point.Y);

        ////    Points[5] = Points[0];
        ////}

        //#region IDrawable 成员

        //public void OnPaint(System.Windows.Forms.PaintEventArgs pe)
        //{
        //    if (points != null)
        //    {
        //        //Pen pen = new Pen(mColor, 2);
        //        //pe.Graphics.DrawLines(pen, points.ToArray());

        //        Brush brush = new SolidBrush(mColor);
        //        pe.Graphics.FillPolygon(brush, points.ToArray());
        //    }
        //}

        //#endregion

        //#region IShape 成员

        //public void MakeShape(PointF point, float fLength)
        //{
        //    //lenth:L
        //    //a circumscribed circle radius: R
        //    //R = L / sin36 * 0.5
        //    float radius = -Math.Abs(fLength / (float)Math.Sin(36.0) * 0.5F);

        //    float lctAngle = (float)(18.0F * Math.PI / 180);
        //    float lcbAngle = (float)(36.0F * Math.PI / 180);

        //    //(0, R)
        //    Points[0] = new PointF(point.X, radius + point.Y);

        //    //(R*cos18, R*sin18)
        //    Points[1] = new PointF(radius * (float)Math.Cos(lctAngle) + point.X,
        //        radius * (float)Math.Sin(lctAngle) + point.Y);

        //    //(R*sin36, -R*cos36)
        //    Points[2] = new PointF(radius * (float)Math.Sin(lcbAngle) + point.X,
        //        -radius * (float)Math.Cos(lcbAngle) + point.Y);

        //    //(-R*sin36, -R*cos36)
        //    Points[3] = new PointF(-radius * (float)Math.Sin(lcbAngle) + point.X,
        //        -radius * (float)Math.Cos(lcbAngle) + point.Y);

        //    //(-R*cos18, R*sin18)
        //    Points[4] = new PointF(-radius * (float)Math.Cos(lctAngle) + point.X,
        //        radius * (float)Math.Sin(lctAngle) + point.Y);

        //    Points[5] = Points[0];
        //}

        //#endregion

        public override void DoMakeShape(PointF point, float fLength)
        {
            //lenth:L
            //a circumscribed circle radius: R
            //R = L / sin36 * 0.5
            float radius = -Math.Abs(fLength / (float)Math.Sin(36.0) * 0.5F);

            float lctAngle = (float)(18.0F * Math.PI / 180);
            float lcbAngle = (float)(36.0F * Math.PI / 180);

            //(0, R)
            Points[0] = new PointF(point.X, radius + point.Y);

            //(R*cos18, R*sin18)
            Points[1] = new PointF(radius * (float)Math.Cos(lctAngle) + point.X,
                radius * (float)Math.Sin(lctAngle) + point.Y);

            //(R*sin36, -R*cos36)
            Points[2] = new PointF(radius * (float)Math.Sin(lcbAngle) + point.X,
                -radius * (float)Math.Cos(lcbAngle) + point.Y);

            //(-R*sin36, -R*cos36)
            Points[3] = new PointF(-radius * (float)Math.Sin(lcbAngle) + point.X,
                -radius * (float)Math.Cos(lcbAngle) + point.Y);

            //(-R*cos18, R*sin18)
            Points[4] = new PointF(-radius * (float)Math.Cos(lctAngle) + point.X,
                radius * (float)Math.Sin(lctAngle) + point.Y);

            Points[5] = Points[0];
        }
    }
}
